package bb.lanxing.util;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import bb.lanxing.App;
import bb.lanxing.R;
import bb.lanxing.activity.PhotoViewerActivity;
import bb.lanxing.common.config.ImagePostfix;
import bb.lanxing.model.json.RankUserDetail;

public class UserAvatarUtil {
    private static UserAvatarUtil userAvatarUtil;

    public static UserAvatarUtil getInstance() {
        if (userAvatarUtil == null) {
            synchronized (UserAvatarUtil.class) {
                if (userAvatarUtil == null) {
                    userAvatarUtil = new UserAvatarUtil();
                }
            }
        }
        return userAvatarUtil;
    }

    public void setUserAvatarUrl(ImageView imageView, String str) {
        if (imageView == null) {
            return;
        }
        if (!TextUtils.isEmpty(str) && str.contains(ImagePostfix.WEB_URL) && !str.endsWith("!avatar")) {
            str = str + "!avatar";
        }
        Glide.with(App.getContext()).load(str).apply(new RequestOptions().placeholder(R.drawable.ic_v1_profile).error(R.drawable.ic_v1_profile).transform(new CircleCrop())).into(imageView);
    }

    public void goToUserInfo(Context context, long j) {
//        Intent intent = new Intent(context, UserProfileActivity.class);
//        intent.putExtra("user_id", j);
//        context.startActivity(intent);
    }

    public void goToUserInfo(Context context, long userId, RankUserDetail rankUser) {
//        Intent intent = new Intent(context, UserProfileActivity.class);
//        intent.putExtra("user_id", userId);
//        intent.putExtra("rank_user", (Parcelable) rankUser);
//        context.startActivity(intent);
        //TODO llkll
        Log.i("UserAvatarUtil", "UserAvatarUtil.goToUserInfo todo check");
    }

    public void showUserAvatarBig(Context context, String str) {
        Intent intent = new Intent(context, PhotoViewerActivity.class);
        intent.putExtra("photo_url", str);
        context.startActivity(intent);
    }
}
